﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Media;

namespace MainGame.GameSound
{

  public enum MenuSounds
  {
    ClickCard = 0,
    Keystroke1 = 1,
    Keystroke2 = 2,
    Keystroke3 = 3,
    Logo = 4,
    NumSounds = 5
  }

  public class MenuSoundManager : SoundManager<MenuSounds>
  {
    public MenuSoundManager(Game game)
      : base(game) { }

    protected override void Dispose(bool disposing)
    {
      base.Dispose(disposing);
    }

    public override void Initialize()
    {
      soundLibrary = new SoundEffect[(int)MenuSounds.NumSounds];
      // Load all menu sounds
      var content = Game.Content;
      soundLibrary[(int)MenuSounds.ClickCard] = content.Load<SoundEffect>(@"Sounds\\cardFlip1");
      soundLibrary[(int)MenuSounds.Keystroke1] = content.Load<SoundEffect>(@"Sounds\\key1");
      soundLibrary[(int)MenuSounds.Keystroke2] = content.Load<SoundEffect>(@"Sounds\\key3");
      soundLibrary[(int)MenuSounds.Keystroke3] = content.Load<SoundEffect>(@"Sounds\\key5");
      soundLibrary[(int)MenuSounds.Logo] = content.Load<SoundEffect>(@"Sounds\\m_Logo");
            
      base.Initialize();
    }
    
    public override void PlaySound(MenuSounds sound)
    {
      if (!SfxMuted)
      {
        int snum = (int)sound;
        SoundEffectInstance sInst = soundLibrary[snum].CreateInstance();
        AddToPlayingQueue(sInst);
        sInst.Play();
      }
    }

    public override void PlaySound(MenuSounds sound, float volume, float pitch, float pan)
    {
      if (!SfxMuted)
      {
        int snum = (int)sound;
        SoundEffectInstance sInst = soundLibrary[snum].CreateInstance();
        AddToPlayingQueue(sInst);

        sInst.Volume = volume;
        sInst.Pitch = pitch;
        sInst.Pan = pan;

        sInst.Play();
      }
    }
  }
}
